//
//  VerifyCodeVC.m
//  LoginTest
//
//  Created by 战立军 on 2017/3/9.
//  Copyright © 2017年 战立军. All rights reserved.
//

#import "VerifyCodeVC.h"
#import "WLUnitField.h"
@interface VerifyCodeVC ()
{
    WLUnitField *_wlUnitField;
    
    UIButton *_sureButton;
    
    CGFloat _myheight;
    CGFloat _headheight;
    CGFloat _wh;
}
@end

@implementation VerifyCodeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //背景色
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.colors = @[(__bridge id)[UIUTils colorFromHexCode:@"0489c2"].CGColor,(__bridge id)[UIUTils colorFromHexCode:@"009c93"].CGColor];
    gradientLayer.locations = @[@0.3,@1.0];
    gradientLayer.startPoint = CGPointMake(0, 0);
    gradientLayer.endPoint = CGPointMake(0, 1.0);
    gradientLayer.frame = self.view.bounds;
    [self.view.layer insertSublayer:gradientLayer atIndex:0];
    
    _myheight = 50;
    _headheight = 64+20;
    _wh = 40;
    if (IS_IPHONE_5) {
        _myheight = 50;
        _headheight = 64+30;
    }
    
    if (IS_IPHONE_6) {
        _myheight = 50;
        _headheight = 64+35;
        _wh = 50;
    }
    if (IS_IPHONE_6P) {
        
        _myheight = 65;
        _headheight = 64+40;
        _wh = 70;
    }

    [self setNav];
    [self addContentView];
    
    // Do any additional setup after loading the view.
}

- (void)setNav
{
    //导航栏颜色
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    //导航栏颜色
    [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"uitabr"]]];
    
    //返回
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"qz_icon_facade_back_light_normal"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPress)];
    leftButton.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = leftButton;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)backButtonPress
{
    [self.view endEditing:YES];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)addContentView
{
    //提示短信
    UILabel *smstext = [[UILabel alloc] initWithFrame:CGRectMake(0, _headheight, [UIUTils getWindowWidth], _myheight)];
    smstext.text = @"短信验证码";
    smstext.textAlignment = NSTextAlignmentCenter;
    smstext.font = [UIFont systemFontOfSize:29];
    smstext.textColor = [UIColor whiteColor];
    smstext.adjustsFontSizeToFitWidth = YES;
//    smstext.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:smstext];
    
    //手机
    
    UILabel *phonetext = [[UILabel alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(smstext.frame), [UIUTils getWindowWidth]-30*2, _myheight)];
    
    if (_userPhone.length>4) {
        phonetext.text = [NSString stringWithFormat:@"已向您尾号 %@ 的手机发送验证码",[_userPhone substringFromIndex:_userPhone.length- 4]];
    }
    phonetext.adjustsFontSizeToFitWidth = YES;
    phonetext.textAlignment = NSTextAlignmentCenter;
    phonetext.textColor = [UIColor whiteColor];
    [self.view addSubview:phonetext];
    
    //验证框
    
    _wlUnitField = [[WLUnitField alloc] initWithInputUnitCount:4];
    _wlUnitField.frame = CGRectMake(_wh, CGRectGetMaxY(phonetext.frame), [UIUTils getWindowWidth]-_wh*2, ([UIUTils getWindowWidth]-_wh*2-6*3)/4);
    
    [self.view addSubview:_wlUnitField];
    
    //确定按钮
    
    _sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _sureButton.frame = CGRectMake(30, CGRectGetMaxY(_wlUnitField.frame)+20, [UIUTils getWindowWidth]-30*2, _myheight);
    _sureButton.backgroundColor = [UIUTils colorFromHexCode:@"#eb6065"];
    [_sureButton setTitle:@"确定" forState:UIControlStateNormal];
    _sureButton.layer.cornerRadius = 10;
    [_sureButton addTarget:self action:@selector(sureButtonPress) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_sureButton];
}

-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

- (void)sureButtonPress
{
    if (_wlUnitField.text.length<4) {
        return;
    }
    [self.view endEditing:YES];
    NSLog(@"####%@",_wlUnitField.text);
    
    //判断输入验证码
    //后台获取登录信息，登录，但是下次不自动登录
}

#pragma mark WLUnitFieldDelegate

@end
